//////////////////////////////////////////////////////////////////////////
//
// This file is a part of APNS provider project.
// Copyright (c) Vladimir Gumenuk, 2013-2014.
//
// PROJECT:         APNS provider
// FILE:            PushNotification.h
// AUTHOR:          Vladimir Gumenuk
// DATE:            22-Dec-2013
// MODIFICATIONS:
//
//////////////////////////////////////////////////////////////////////////

#pragma once

//////////////////////////////////////////////////////////////////////////
// Rerpesents the single Push Notification entity.
// Supports all Apple defined binary formats
class ATL_NO_VTABLE CPushNotification :
    public CComObjectRootEx<CComMultiThreadModel>,
    public IPushNotification
{
public:
    CPushNotification();
    virtual ~CPushNotification();

    static HRESULT Create( IPushNotification **ppOut );

BEGIN_COM_MAP(CPushNotification)
    COM_INTERFACE_ENTRY_IID(IID_IPushNotification,IPushNotification)
END_COM_MAP()

    STDMETHOD (Init)( DWORD dwExpiration, BYTE bPriority, const DeviceToken& deviceToken, LPCSTR lpszPayload );
    STDMETHOD (SetPayload)( LPCSTR lpszPayload );
    STDMETHOD (Makeup)( DWORD dwType, IGMSBuffer **ppOut );
    STDMETHOD_(DWORD,GetID)() { return m_dwID; }

private:
    HRESULT PrepareNtfFormat0( IGMSBuffer *pBuf );
    HRESULT PrepareNtfFormat1( IGMSBuffer *pBuf );
    HRESULT PrepareNtfFormat2( IGMSBuffer *pBuf );

    LPBYTE storeBYTE( LPBYTE p, BYTE dwValue );
    LPBYTE storeWORD( LPBYTE p, WORD dwValue );
    LPBYTE storeDWORD( LPBYTE p, DWORD dwValue );
    LPBYTE storeBLOCK( LPBYTE p, LPBYTE pValue, DWORD dwSize );
    LPBYTE storeSTRING( LPBYTE p, LPCSTR lpszValue );

    DWORD           m_dwID;         // must be unique for all notifications
    DWORD           m_dwExpiration;
    BYTE            m_bPriority;
    DeviceToken     m_Token;
    LPSTR           m_lpszPayload;
};